package org.xserver.disruptor.producer;

import java.lang.reflect.Method;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import org.xserver.component.spring.SpringUtil;
import org.xserver.disruptor.annotation.EventConsumer;

import com.lmax.disruptor.EventHandler;

@EventConsumer
@Service
public class WebsocketMessageEventConsumer implements EventHandler<WebsocketEvent>{
	private final static Logger logger = LoggerFactory.getLogger(WebsocketMessageEventConsumer.class);
	@Override
	public void onEvent(WebsocketEvent event, long sequence, boolean endOfBatch)
			throws Exception {
		Object websocketInterface = SpringUtil.getBean(event.getClazz());
		Method method = event.getMethod();
    	Object[] parameters = new Object[]{event.getWxMessage(),event.getChannelId()};
    	method.invoke(websocketInterface, parameters);
	}
}
